﻿@using JabbR
@using JabbR.ViewModels
@using SquishIt.Framework
@model ProfilePageViewModel

@{
    var userModel = Model;
    var gravatar = String.Format("https://secure.gravatar.com/avatar/{0}?s=48&d=mm", userModel.Hash);
    var passwordUrl = userModel.HasPassword ? Url.Content("~/account/changepassword") : Url.Content("~/account/newpassword");
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>JabbR - account</title>
    @{ 
        WriteLiteral(Bundle.Css()
            .Add("~/Content/bootstrap.min.css")
            .Add("~/Content/bootstrap-responsive.min.css")
            .Add("~/Content/font-awesome.min.css")
            .Add("~/Content/themes/default/Chat.css")
            .Add("~/Content/emoji20.css")
            .Render("~/Content/JabbR_#.css"));
    }
</head>
<body class="user-profile">
    <section id="page" role="application">
        <header id="heading" role="heading">
            <div class="banner" role="banner">
                <h1>JabbR</h1>
            </div>
            <div style="clear: both"></div>
        </header>
        <div class="container">
            <div class="row" style="padding-top: 75px;">
                @Html.AlertMessages()
                <div class="row">
                    <div class="span12">
                        <div class="user-details">
                            <img class="gravatar" src="@gravatar" />
                            <span class="name">@userModel.Name</span>
                        </div>
                        <hr />
                    </div>
                </div>
                <div class="tabbable tabs-left">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#profile" data-toggle="tab">@LanguageResources.Account_Profile</a></li>
                        <li><a href="#changeUsername" data-toggle="tab">@LanguageResources.Account_UserName</a></li>
                        <li><a href="#changePassword" data-toggle="tab">@LanguageResources.Account_Pass</a></li>
                        @if (userModel.SocialDetails.ConfiguredProviders.Any())
                        {
                            <li><a href="#identityProviders" data-toggle="tab">@LanguageResources.Account_IdentityProviders</a></li>
                        }
                    </ul>
                    <div class="tab-content">
                        <div class="account-details tab-pane active" id="profile">
                            <form class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label" for="note">@LanguageResources.Account_Note</label>
                                    <div class="controls">
                                        <label class="control-label label-align-left">@(userModel.Note ?? "-")</label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="country">@LanguageResources.Account_Country</label>
                                    <div class="controls">
                                        <label class="control-label label-align-left">@(userModel.Country ?? "-") <span class="flag flag-@userModel.Flag"></span></label>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="account-details tab-pane hide" id="changeUsername">
                            <form class="form-horizontal" action="@Url.Content("~/account/changeusername")#changeUsername" method="POST">
                                @Html.ValidationSummary()
                                <div class="control-group">
                                    <label class="control-label" for="username">@LanguageResources.Account_UserName</label>
                                    <div class="controls">
                                        @Html.TextBox("username", "input-xlarge", LanguageResources.Account_UserName)
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="confirmUsername">@LanguageResources.Account_UserNameConfirm</label>
                                    <div class="controls">
                                        @Html.TextBox("confirmUsername", "input-xlarge", LanguageResources.Account_UserNameConfirm)
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input type="submit" class="btn" value="@LanguageResources.Account_ChangeUserName" />
                                    </div>
                                </div>
                                @Html.AntiForgeryToken()
                            </form>
                        </div>
                        <div class="account-details tab-pane hide" id="changePassword">
                            <form class="form-horizontal" action="@passwordUrl#changePassword" method="POST">
                                @Html.ValidationSummary()
                                @if (userModel.HasPassword)
                                {
                                    <div class="control-group">
                                        <label class="control-label" for="oldPassword">@LanguageResources.Account_CurrentPass</label>
                                        <div class="controls">
                                            @Html.Password("oldPassword", "input-xlarge", LanguageResources.Account_CurrentPass)
                                        </div>
                                    </div>
                                }
                                <div class="control-group">
                                    <label class="control-label" for="password">@LanguageResources.Account_Pass</label>
                                    <div class="controls">
                                        @Html.Password("password", "input-xlarge", LanguageResources.Account_Pass)
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="confirmPassword">@LanguageResources.Account_PassConfirm</label>
                                    <div class="controls">
                                        @Html.Password("confirmPassword", "input-xlarge", LanguageResources.Account_PassConfirm)
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input type="submit" class="btn" value="@LanguageResources.Account_ChangePass" />
                                    </div>
                                </div>
                                @Html.AntiForgeryToken()
                            </form>
                        </div>
                        <div class="account-details tab-pane hide" id="identityProviders">
                            @Html.Partial("_social", @userModel.SocialDetails)
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script src="@Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script>
    <script src="@Url.Content("~/Scripts/bootstrap.min.js")"></script>
    <script type="text/javascript">
        (function ($) {
            // set the selected tab based on the hash
            var currentSection = document.location.hash || "#profile";
            $('a[href="' + currentSection + '"]').tab('show');

            // always set the hash when we change tabs
            $('a[data-toggle="tab"]').on('shown', function (e) {
                document.location.hash = e.target.hash;
            });

            // make sure errors look pretty and bootstrap-y
            $('input.error').closest('.control-group').addClass('error');
        }(jQuery));
    </script>
</body>
</html>
